package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import com.sky.vo.TurnoverVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    /*
    * 往订单表插入数据
    * */
    void insert(Orders orders);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /*
    * 绕过支付，更新数据库支付状态
    * */
    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{checkOutTime} " +
            "where number = #{orderNumber}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkOutTime, String orderNumber);

    /**
     * 分页查询
     * @param
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /*
    * 根据订单id查询订单
    * */
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    /*
    * 订单条件查询
    * */
    Page<OrderVO> selectByDTO(OrdersPageQueryDTO ordersPageQueryDTO);

    /*
    * 获取待派送的订单数量
    * */
    @Select("select count(0) from orders where status = 3")
    Integer selectCountByConf();

    /*
    * 获取派送中的订单数量
    * */
    @Select("select count(0) from orders where status = 4")
    Integer selectCountByDelivery();

    /*
    * 获取待接单的数量
    * */
    @Select("select count(0) from orders where status = 2")
    Integer selectCountByToBeConf();

    /*
    * 查询超时订单
    * */
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);

    /*
    * 根据日期计算出每天的营业额
    * */
    List<TurnoverVo> getByDate();

    /*
    * 根据订单状态查询
    * */
    Integer selectCountByStatus(List<Integer> status, LocalDate time);

    /*
    * 根据状态分类获取指定日期的订单数量
    * */
    List<OrderVO> getorderCount(LocalDate end,List<Integer> status);

    /*
    * 获取排名的top10的商品的名字
    * */
    List<OrderDetail> getNameTop10(LocalDate begin, LocalDate end);

    /*
    * 获取今天的营业额
    * */
    Double getTodayTurnover(LocalDate today);

    /**
     * 根据状态查询今日订单数据
     * @param today
     * @param status
     * @return java.lang.Integer
     * @author zhupp
     * @create 2025/3/1
     **/
    Integer getByStatusToday(LocalDate today, Integer status);
}
